package com.jun.common.core.entity.page;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.List;

/**
 * @author yuejun.li
 * @date 2023/7/13 13:32:21
 */
@Data
public class PageResult<T> {

    /**
     * 当前页码
     */
    private Integer pageNum;
    /**
     * 每页数量
     */
    private Integer pageSize;
    /**
     * 总页数
     */
    private Integer totalPage;
    /**
     * 总条数
     */
    private Long total;
    /**
     * 分页数据
     */
    private List<T> items;

    /**
     * 将Page分页后的list转为分页信息
     */
    public static <T> PageResult<T> restPage(Page<T> list) {
        PageResult<T> result = new PageResult<T>();
        result.setTotalPage(list.getPages());
        result.setPageNum(list.getPageNum());
        result.setPageSize(list.getPageSize());
        result.setTotal(list.getTotal());
        result.setItems(list.getResult());
        return result;
    }
}
